<template>
  <div class="member-add flex-column" v-loading="loading">
    <el-form :model="form" :rules="rules" :label-width="100">
      <el-form-item label="部门成员" prop="user" class="worker">
        <Icon icon="plus" class="worker-add click" @click="setDesign({})"></Icon>
        <el-select-v2
          class="width-100"
          v-model="form.user"
          :options="options"
          multiple
          clearable
          collapse-tags
          collapse-tags-tooltip
          :max-collapse-tags="9"
          placeholder="请输入用户账号"
        >
          <template #prefix><span></span></template>
        </el-select-v2>
      </el-form-item>
      <el-form-item label="设立主管" prop="password">
        <el-radio-group v-model="form.auth" class="">
          <el-radio label="1">是</el-radio>
          <el-radio label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="管理权限" prop="username">
        <el-radio-group v-model="form.auth" class="">
          <el-radio label="1">可分配</el-radio>
          <el-radio label="2">不可分配</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="员工职位" prop="username">
        <el-radio-group v-model="form.auth" class="">
          <el-radio label="1">总监</el-radio>
          <el-radio label="2">专监</el-radio>
          <el-radio label="3">资料员</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="功能权限" prop="username">
        <div class="flex-row-between card-permission">
          <el-card class="" shadow="never">
            <div v-for="group in groups" :key="group">
              <el-checkbox v-model="group.selected" :indeterminate="isIndeterminate()" @change="handleCheckAllChange">
                {{ group.name }}
              </el-checkbox>
              <div v-for="item in group.children" :key="item">
                <el-space class="" :size="60">
                  <el-checkbox class="margin-right-10px" v-model="item.selected">{{ item.name }}</el-checkbox>
                  <el-radio-group v-model="item.auth" class="">
                    <el-radio label="1">可查看</el-radio>
                    <el-radio label="2">可编辑</el-radio>
                  </el-radio-group>
                </el-space>
              </div>
            </div>
          </el-card>
          <el-card shadow="never">
            <div v-for="group in groups" :key="group">
              <el-checkbox v-model="group.selected" :indeterminate="isIndeterminate()" @change="handleCheckAllChange">
                {{ group.name }}
              </el-checkbox>
              <div v-for="item in group.children" :key="item">
                <el-space class="" :size="60">
                  <el-checkbox class="margin-right-10px" v-model="item.selected">{{ item.name }}</el-checkbox>
                  <el-radio-group v-model="item.auth" class="">
                    <el-radio label="1">可查看</el-radio>
                    <el-radio label="2">可编辑</el-radio>
                  </el-radio-group>
                </el-space>
              </div>
            </div>
          </el-card>
        </div>
      </el-form-item>

      <div class="form-action text-center">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="save">确认</el-button>
      </div>
    </el-form>
    <el-dialog
      width="860px"
      title="人员管理"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :model-value="designWorker ? true : false"
      @close="setDesign()"
    >
      <DesignWorker v-if="designWorker" :design="design" @close="setDesign()"></DesignWorker>
    </el-dialog>
  </div>
</template>

<script>
import BaseComponent from "@/application/BaseComponent.vue";
import DesignWorker from "./DesignWorker.vue";

export default {
  extends: BaseComponent,
  name: "MemberDesign",
  components: { DesignWorker },
  props: ["design"],
  emits: ["close"],
  data() {
    return {
      designWorker: null,
      options: [
        { label: "张三", value: "张三" },
        { label: "张三1", value: "张三1" },
        { label: "张三2", value: "张三2" },
        { label: "张三3", value: "张三3" }
      ],
      loading: false,
      form: this.design || {},
      rules: [],
      groups: [
        {
          name: "数字员工",
          children: [
            { name: "数字状态", children: [] },
            { name: "工作记录", children: [] }
          ]
        }
      ]
    };
  },
  computed: {
    checkAll() {
      return 0;
    },
    groups1() {
      return [
        {
          name: "数字员工",
          children: [
            { name: "数字状态", children: [] },
            { name: "工作记录", children: [] }
          ]
        }
      ];
    }
  },
  created() {
    // this.getData();
  },

  methods: {
    setDesign(design) {
      this.designWorker = design;
    },
    isIndeterminate() {},
    handleCheckAllChange() {},
    cancel() {
      this.$emit(`close`);
    },
    save() {
      this.loading = true;
      this.$g.ajax.$api("member.save", this.form).then((result) => {
        console.log(result);
        this.loading = false;
        this.$g.toast(result.message, result.code == 0 ? "success" : "error");
        this.cancel();
      });
    }
  }
};
</script>
<style>
.member-add {
  border-radius: 8px 8px 8px 8px;
  position: absolute;
  inset: 0;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  background: white;
  z-index: 9;
  padding: 20px 0;
  overflow: auto;
}
.member-add .el-form {
  max-width: 900px;
}
.card-permission {
  width: 100%;
}
.card-permission .el-card {
  background-color: rgb(246, 246, 246);
  width: 49%;
  padding: 10px;
}
.el-form-item__content {
  position: relative;
}
.worker-add {
  position: absolute;
  z-index: 100;
  left: 5px;
}
.worker .el-select-v2__wrapper {
  padding-left: 10px;
}
</style>
